import requests
import json



class NeqReq:
	def __init__(self):
		self.session = requests.session()
	
	def reset(self):
		self.session.cookies.clear()
		self.session.headers.clear()

	def send_request(self, method:str, url:str, data:dict={} , data_type:str= 'data',):
	
		method = method.upper()

		kwargs = {}

		if method in ['GET', 'DELETE']:
			kwargs['params'] = data
		else:
			if data_type == 'data':
				kwargs['data'] = data
			else:
				kwargs['json'] = data
		
		resp = self.session.request(method, url, **kwargs)

		resp.encoding = "utf-8"
		
		try:
			body = json.loads(resp.text)
		except Exception:
			# print(resp.text)
			body = {}

		return {
			"code":resp.status_code,
			"body":body
		}


